package lancooControl;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.example.lancooznbk.R;


/**
 * dialog
 * @author wgl
 *
 */
public class ClearCacheDialog extends Dialog{
	
//	public static RelativeLayout layout_bg;

	private Context mContext;
	private ClickListenerInterface clickListenerInterface;
	public static Button BtnEnsure;
	public static Button BtnCancle;
	private TextView tv_cache_size;

	public interface ClickListenerInterface {
		public void doEnsure();
		public void doCancle();
	}
	
	public ClearCacheDialog(Context context) {
		super(context, R.style.CustomDialog);
		this.mContext = context;;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {  
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.dialog_clear_cache);
		
		getWindow().setBackgroundDrawableResource(R.color.vifrification);

//		layout_bg = (RelativeLayout) findViewById(R.id.layout_bg);
		
		Log.d("bb","------long-------####****##-0000000-----------------");

		
		tv_cache_size = (TextView) findViewById(R.id.textview_cache_size);
		try {
//			tv_cache_size.setText(DataCleanManager.getTotalCacheSize(getContext()));
			String str_cache_size = CacheCleanManager.getTotalCacheSize(getContext());
			if(str_cache_size.equals("0K")){
				tv_cache_size.setText("无缓存可清理！");
			}else {
				tv_cache_size.setText(Html.fromHtml("清理系统缓存文件" + "<font color='#ff0000'><big><big>" + str_cache_size + "</big></big></font>"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		BtnEnsure = (Button) findViewById(R.id.button_ensure);
		BtnEnsure.setOnClickListener(new clickListener());

		BtnCancle = (Button) findViewById(R.id.button_cancle);
		BtnCancle.setOnClickListener(new clickListener());
		
		setCanceledOnTouchOutside(false);
	}

	public void setClicklistener(ClickListenerInterface clickListenerInterface) {
		this.clickListenerInterface = clickListenerInterface;
	}


	private class clickListener implements View.OnClickListener {
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			int id = v.getId();
			switch (id) {
				case R.id.button_ensure:
					System.out.println("------long-------cancle cancle  cancle----------------");
					clickListenerInterface.doEnsure();
					break;

				case R.id.button_cancle:
					clickListenerInterface.doCancle();
					break;

				default:
					System.out.println("-----ooooooo11111defalt----------------");
					break;
			}
		}

	};
	
	 public boolean onKeyDown(int keyCode, KeyEvent event) { 
	        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { 
	        	Log.d("***onKeyDown**","-----------------3333333333333333-----"); 
//	        	FragmentSetting.clearCacheBtn.setSelected(false);
	        	ClearCacheDialog.this.dismiss();
	            return false; 
	        } 
	        return false; 
	    }

}
